﻿
using log4net;
using log4net.Config;
using log4net.Repository;
using System.Collections.Generic;
using System.IO;

namespace Utils
{

    public static class LogNetDebug
    {
        public static List<string> ErrorInfoList = new List<string>();

        private static ILog m_Log;
        // public static ILoggerRepository repository { get; set; }
        static LogNetDebug()
        {
            ILoggerRepository repository = LogManager.CreateRepository("Repository");
            XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
            m_Log = LogManager.GetLogger(repository.Name, "log4net");

        }

        public static void Log(object message)
        {
            m_Log.Debug(message);
        }

        //public static void Log(string format, params object[] args)
        //{
        //    //m_Log.DebugFormat(format, args);       
        //    m_Log.Debug(format);
        //}

        public static void LogInfo(object message)
        {
            m_Log.Info(message);
        }

        public static void LogInfo(string format, params object[] args)
        {
            m_Log.InfoFormat(format, args);
        }

        public static void LogWarn(object message)
        {
            m_Log.Warn(message);
        }

        public static void LogWarn(string format, params object[] args)
        {
            m_Log.WarnFormat(format, args);
        }

        public static void LogError(object message)
        {

            m_Log.Error(message);
        }

        public static void LogError(string format, params object[] args)
        {
            if (!ErrorInfoList.Contains(format))
                ErrorInfoList.Add(format);
            m_Log.ErrorFormat(format, args);
        }

        public static void LogErrorUnSave(string format)
        {
            m_Log.ErrorFormat(format);
        }


        /// <summary>
        /// 灾难级别的
        /// </summary>
        /// <param name="message"></param>
        public static void LogFatal(object message)
        {
            m_Log.Fatal(message);
        }

        public static void LogFatal(string format, params object[] args)
        {
            m_Log.FatalFormat(format, args);
        }
    }
}

